//
//  Js_StringValidator.m
//  JsoUtilitySdk
//
//  Created by Gikki Ares on 2022/4/21.
//

#import "JsStringValidator.h"

@implementation JsStringValidator

+ (BOOL)isStirng:(NSString *)string matchRegularSring:(NSString *)regularString {
	NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",regularString];
	BOOL isMatch = [predicate evaluateWithObject:string];
	return isMatch;
}

+ (BOOL)isValidUrlString:(NSString *)urlString {
	NSString * regString = @"^http(s)?://.*";
//	NSString * regString = @"^http(s)?://([\\w-]+\\.)+[\\w-]+(/[\\w- ./?%&=]*)?";
	if(![self isStirng:urlString matchRegularSring:regString]) {
		return NO;
	}
	return YES;
}
+ (BOOL)isValidRtmpString:(NSString *)urlString {
	NSString * regString = @"^rtmp://.*";
//	NSString * regString = @"^rtmp://([\\w-]+\\.)+[\\w-]+(/[\\w- ./?%&=]*)?";
	if(![self isStirng:urlString matchRegularSring:regString]) {
		return false;
	}
	if(urlString.length < 10) {
		return false;
	}
	return true;
}

+ (BOOL)isValidHlsString:(NSString *)urlString {
	if(![self isValidUrlString:urlString]) {
		return NO;
	}
	if(urlString.length < 10) {
		return NO;
	}
	if(![urlString containsString:@".m3u8"]) {
		return NO;
	}
	return YES;
}

+ (BOOL)isOnlyContainNumAndCh:(NSString *)string; {
	NSString * regString = @"[\\da-zA-Z]+";
		//	NSString * regString = @"^rtmp://([\\w-]+\\.)+[\\w-]+(/[\\w- ./?%&=]*)?";
	if(![self isStirng:string matchRegularSring:regString]) {
		return false;
	}
	return true;
}

+ (BOOL)isOnlyContainNumChU:(NSString *)string {
	NSString * regString = @"[\\da-zA-Z_]+";
		//	NSString * regString = @"^rtmp://([\\w-]+\\.)+[\\w-]+(/[\\w- ./?%&=]*)?";
	if(![self isStirng:string matchRegularSring:regString]) {
		return false;
	}
	return true;
}

@end
